@layout("/common/_container.html",{js:["/assets/modular/system/project/project_internetStore.js"]}){
<style>
    .input{
        border:none;
    }
    .editinput{
        width:230px;
    }
    .name{
        font-weight: bold;
        color: #0C0C0C;
    }
    .layui-table tbody tr:hover,
    .layui-table thead tr,
    .layui-table-click,
    .layui-table-header,
    .layui-table-hover,
    .layui-table-mend,
    .layui-table-patch, .layui-table-tool,
    .layui-table-total, .layui-table-total tr, .layui-table[lay-even] tr:nth-child(even) {
        background-color: #FFFFFF;
    }
    td{
        white-space: nowrap;
    }
</style>
<div class="testdiv" id="table">
    <table class="layui-table" style="width: 50%;margin: 0 auto" border="1px" id="tables">
        <thead>
        <tr id="tr">
            <th class="name">分店名称</th>
            <th class="name">对外门店名称</th>
            <th class="name">详细地址</th>
            <th class="name">点餐电话</th>
            <th class="name">公司归属</th>
            <th class="name">每日营业时间</th>
        </tr>
        </thead>
        <tbody id="tbody">
        <tr>
            <td><input class="input editinput" id="fdName"/></td>
            <td><input class="input editinput" id="mdName"/></td>
            <td><input class="input editinput" id="address"/></td>
            <td><input class="input editinput" id="dcPhone"/></td>
            <td><input class="input editinput" id="company"/></td>
            <td><input class="input editinput" id="business"/></td>
        </tr>
        </tbody>
    </table>
</div>
<div class="layui-inline" style="margin-top: 20px;margin-left: 20px">
    <a id="dlink"  style="display:none;"></a>
    <button  class="layui-btn icon-btn" onclick="tableToExcel('tables', 'name', '网上建店.xls')"><i class="layui-icon">&#xe67d;</i>下载
    </button>
    <button id="btnKeep" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>保存
    </button>
    <button id="backupPage" class="layui-btn icon-btn">返回
    </button>
</div>
@}
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="application/javascript">
    const id = '${id}';
    const lists = [${list}];

    var list = [];

    $(function () {
        for (let i = 0; i < lists[0][0].length; i++) {
            let pinCode = lists[0][0][i].pinCode;
            $("#" + pinCode + "").val(lists[0][0][i].data);
            $("#" + pinCode + "").attr("readonly", true);
        }
    });

    $('#btnKeep').click(function () {
        for (let i = 1; i < 6; i++) {
            var object = {};
            if (i == 1) {
                object.mouldId = "34";
                object.proId = id;
                object.data = $('#fdName').val();
                object.pinCode = "fdName";
            } else if (i == 2) {
                object.data = $('#mdName').val();
                object.pinCode = "mdName";
            } else if (i == 3) {
                object.data = $('#address').val();
                object.pinCode = "address";
            } else if (i == 4) {
                object.data = $('#dcPhone').val();
                object.pinCode = "dcPhone";
            } else if (i == 5) {
                object.data = $('#company').val();
                object.pinCode = "company";
            } else if (i == 6) {
                object.data = $('#business').val();
                object.pinCode = "business";
            }
            object.dataType = 1;
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/mouldBoardMsg/add",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function () {
                list = [];
                window.location.reload();

            }, error: function () {
                list = [];
                window.location.reload();
            }
        });
    })
    /**
     * 导出excel按钮
     */
    var tableToExcel = (function () {
        var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
            base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
            format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) };
        return function (table, name, filename) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
            document.getElementById("dlink").href = uri + base64(format(template, ctx));
            document.getElementById("dlink").download = filename;
            document.getElementById("dlink").click();
        }
    })()
</script>


